//
//  ByCheckAccountCell.m
//  recordworktool_ios
//
//  Created by mc on 2017/12/9.
//  Copyright © 2017年 ZhangZhanbin. All rights reserved.
//

#import "ByCheckAccountCell.h"

@implementation ByCheckAccountCell

+ (instancetype)cellWithTableView:(UITableView*)tableView {
    
    static NSString *cellIdentifier = @"ByCheckAccountCell";
    ByCheckAccountCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
    
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self createViews];
    }
    return self;
}


- (void)createViews{
    
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    UIView *view = [[UIView alloc] init];
    [self.contentView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.top.equalTo(self.contentView).offset(0);
        make.bottom.equalTo(self.contentView).offset(-5);
    }];
    view.backgroundColor = rgba(230, 246, 254, 1);
    view.layer.cornerRadius = 10;
    
    CGFloat width = (SCREEN_WIDTH - 20) / 4;
    UILabel *timeLabel = [[UILabel alloc] init];
    [view addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(view.mas_centerX).offset(0);
        make.centerY.equalTo(view).offset(0);
        make.size.mas_equalTo(CGSizeMake(width ,20));
    }];
    timeLabel.textAlignment = NSTextAlignmentCenter;
    timeLabel.text = @"2017-10-9";
    timeLabel.font = FONT(12);
    timeLabel.textColor = TEXT_COLOR;
    
    
    UIButton *detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [view addSubview:detailBtn];
    [detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(view).offset(-(width - 60) / 2);
        make.centerY.equalTo(view).offset(0);
        make.size.mas_equalTo(CGSizeMake(60, 22));
    }];
    detailBtn.titleLabel.font = FONT(12);
    [detailBtn setTitle:@"明细" forState:UIControlStateNormal];
    [detailBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    detailBtn.layer.cornerRadius = 10;
    [detailBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel *nameLabel = [[UILabel alloc] init];
    [view addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).offset(0);
        make.centerY.equalTo(view).offset(0);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    nameLabel.font = FONT(12);
    nameLabel.textColor = TEXT_COLOR;
    nameLabel.text = @"王工头";
    nameLabel.textAlignment = NSTextAlignmentCenter;
    
    UILabel *priceLabel = [[UILabel alloc] init];
    [view addSubview:priceLabel];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_centerX).offset(0);
        make.centerY.equalTo(view).offset(0);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    priceLabel.font = FONT(12);
    priceLabel.textColor = TEXT_COLOR;
    priceLabel.text = @"¥500";
    priceLabel.textAlignment = NSTextAlignmentCenter;
    
    self.timeLabel = timeLabel;
    self.nameLabel = nameLabel;
    self.priceLabel = priceLabel;
    self.detailBtn = detailBtn;
}

- (void)btnAction:(UIButton *)btn{
    //已核对
    if (_netModel.audit_status.integerValue == 1) {
        return;
    }
    self.detailAction();
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    if (BY_USER.isWorker.integerValue == 1) {
        self.nameLabel.text = _netModel.overseer_name;
    }else{
        self.nameLabel.text = _netModel.worker_name;
    }
    
    self.timeLabel.text = [NSDate getDateForStringFotmatWithTimeInterval:_netModel.create_time.integerValue formatter:@"yyyy-MM-dd"];
    self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f", _netModel.money.floatValue];
    
    //待核对
    if (_netModel.audit_status.integerValue == 0) {
        self.detailBtn.backgroundColor = BY_THEME_COLOR;
        [self.detailBtn setTitle:@"待核对" forState:UIControlStateNormal];
    //已核对
    }else if (_netModel.audit_status.integerValue == 1){
        self.detailBtn.backgroundColor = rgba(144, 144, 144, 1);
        [self.detailBtn setTitle:@"已核对" forState:UIControlStateNormal];
    }else if (_netModel.audit_status.integerValue == 2){
        
        self.detailBtn.backgroundColor = [UIColor redColor];
        [self.detailBtn setTitle:@"存疑" forState:UIControlStateNormal];
    }
              
    
}

@end
